<?php
		
if($_GET['action']=='home'){
		direct_url();
		$cache = new Cache();
		
		$sql ="select id, post_id, is_video,views,likes,comments from index_post where is_video=1 and pick=1 order by id DESC";
		$sql2="select id from index_post where is_video=1 and pick=1";
			
		$pager = new Pagination($sql,VIDEO_ITEMS,4,'',0,"post");

	
		$data['pick'] = $pager->paginate($cache,$sql2);

	
		$total= $pager->total_rows;
		
		$data['video_pages'] = ceil($total / VIDEO_ITEMS);
		if($data['video_pages'] > VIDEO_MAX_PAGE){
			$data['video_pages'] = VIDEO_MAX_PAGE;
		}
		
		
		
	$sql ="select * from index_post where is_video=1  order by id desc";
	$sql2="select id from index_post where is_video=1";
	$url=HOME."video/";
	$pager = new Pagination($sql,15,6,$url,500,"post");
	$pager->setDebug(false);
	$data[info] = $pager->paginate($cache,$sql2);
	$data[nav]	= $pager->renderFullNav();
	$data['page']=$pager->get_num_page();
			
			$data1[title]=web_title('Kho Video Clip Hay');
			$data['mota']=web_des("Kho video clip tổng hợp hay nhất");
			$data['keyword']=web_keyword("video clip,kho video clip,clip hay");
			loadview('template/header',$data1);
			loadview("news/list_news_video",$data);
} // End action home

if($_GET['action']=='category'){
	direct_url();
	$data['category']=cache_get_category(intval($_GET['id']));
	$cache=new Cache;
	$sql ="select * from index_post where is_video=1 and cat_id=".intval($_GET['id'])."  order by id desc";
	$sql2="select id from index_post where is_video=1 and cat_id=".intval($_GET['id']);
	//$url=HOME."index.php?module=news&act=type&type=video&action=category&id=".intval($_GET['id'])."&page=";
	$url=HOME.'video/c'.intval($_GET['id']).'/'.$data['category']['alias'].'/';
	$pager = new Pagination($sql,15,6,$url,500,"post");
	$pager->setDebug(false);
	$data[info] = $pager->paginate($cache,$sql2);
	$data[nav]	= $pager->renderFullNav();
	
			
			$data1[title]=web_title($data['category']['seo_title']);
			$data1['keyword']=web_keyword($data['category']['seo_keyword']);
			$data['mota']=web_des($data['category']['seo_description']);
			loadview('template/header',$data1);
			loadview("news/list_news_video_category",$data);
} // End of action category
			
			
if($_GET['action']=='subcategory'){
	direct_url();
	$data['subcategory']=cache_get_category(intval($_GET['id']));
	$data['category']=cache_get_category($data['subcategory']['p_id']);
	
	$cache=new Cache;
	$sql ="select * from index_post where is_video=1 and sub_id=".intval($_GET['id'])."  order by id desc";
	$sql2="select id from index_post where is_video=1 and sub_id=".intval($_GET['id']);
	//$url=HOME."index.php?module=news&act=type&type=video&action=subcategory&id=".intval($_GET['id'])."&page=";
	$url=HOME.'video/s'.intval($_GET['id']).'/'.$data['subcategory']['alias'].'/';
	$pager = new Pagination($sql,15,6,$url,500,"post");
	$pager->setDebug(false);
	$data[info] = $pager->paginate($cache,$sql2);
	$data[nav]	= $pager->renderFullNav();
	
			
			$data1[title]=web_title($data['subcategory']['seo_title']);
			$data1['keyword']=web_keyword($data['subcategory']['seo_keyword']);
			$data['mota']=web_des($data['subcategory']['seo_description']);
			loadview('template/header',$data1);
			loadview("news/list_news_video_subcategory",$data);
} // End of action subcategory
if($_GET['action']=='user'){
	direct_url();
	$db=new db;
	$db->connect();
	$cache=new Cache;
	$sql ="select * from index_post where is_video=1 and username='".mysql_real_escape_string($_GET['id'])."'  order by id desc";
	$sql2="select id from index_post where is_video=1 and username='".mysql_real_escape_string($_GET['id'])."'";
	//$url=HOME."index.php?module=news&act=type&type=video&action=subcategory&id=".intval($_GET['id'])."&page=";
	$url=HOME.'video/user/'.$_GET['id'].'/';
	$pager = new Pagination($sql,15,6,$url,500,"post");
	$pager->setDebug(false);
	$data[info] = $pager->paginate($cache,$sql2);
	$data[nav]	= $pager->renderFullNav();
	
			
			$data1[title]=web_title("Video của ".$_GET['id']);
			$data1[mota]=web_des("Video của ".$_GET['id']);
			$data1[keyword]=web_keyword("Video ,kenh video,video channel,".$_GET['id']);
			loadview('template/header',$data1);
			loadview("news/list_news_video_user",$data);
} // End of action user

if($_GET['action']=='playlist'){
	direct_url();
	$data['album']=cache_get_album(intval($_GET['id']));
	$db=new db;
	$db->connect();
	$cache=new Cache;
	$sql ="select * from index_post where is_video=1 and album_id= ".intval($_GET['id'])."  order by id desc";
	$sql2="select id from index_post where is_video=1 and album_id=".intval($_GET['id'])."";
	$db->close();
	$url=HOME."video/playlist/".$_GET['id'].'.html/';
	$pager = new Pagination($sql,10,6,$url,0,"post");
	$pager->setDebug(false);
	$data[info] = $pager->paginate($cache,$sql2);
	$data[nav]	= $pager->renderFullNav();
	
			
			$data1[title]=web_title($data['album']['name']);
			if($data['album']['title']==""){
				$data1[title]=web_title($data['album']['name']);
			}else{
				$data1[title]=web_title($data['album']['title']);
			}
			if($data['album']['keyword']==""){
				$data1[keyword]=$data['album']['name'].','.khongdau($data['album']['name']);
			}else{
				$data1[keyword]=$data['album']['keyword'];
			}
			
			if($data['album']['description']==""){
				$data1[mota]=$data['album']['name'];
			}else{
				$data1[mota]=$data['album']['description'];
			}
			
			loadview('template/header',$data1);
			loadview("news/list_news_video_album",$data);
} // End of action user